package com.booter.ws.valid;


import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class StrLengthValidator implements ConstraintValidator<StrLengthValid, String> {

    private long max = 1;
    private long min = 1;

    @Override
    public void initialize(StrLengthValid constraintAnnotation) {
        max = constraintAnnotation.max();
        min = constraintAnnotation.min();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(value == null){
            return true;
        }
        return value.trim().length()>=min && value.trim().length()<=max;
    }
}
